package demo.spring.framework.web.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.OncePerRequestFilter;

/**
 * @see demo.javax.filter.FilterDemo
 * @see org.springframework.web.filter.CharacterEncodingFilter
 *
 */
public class OncePerRequestFilterDemo extends OncePerRequestFilter {

    private static Logger logger = LoggerFactory.getLogger(OncePerRequestFilterDemo.class);

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
        // 在DispatcherServlet之前执行
        logger.info("############TestFilter1 doFilterInternal executed############");
        filterChain.doFilter(request, response);
        // 在视图页面返回给客户端之前执行，但是执行顺序在Interceptor之后
        logger.info("############TestFilter1 doFilter after############");
    }
}
